package org.zyj.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zyj.dao.ProductMapper;
import org.zyj.entity.Catagory;
import org.zyj.entity.Product;
import org.zyj.utils.PageBean;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service("ProductService")
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductMapper productMapper;
	
	@Override
	public PageBean<Product> findPageProduct(Integer current) {
		
		if(current==null) {
			current = 1;
			
		}
		
		
		 Integer pageSize = 3;
		/* Integer starRow = (current-1)*3;
		 List<Product> findProduct = productMapper.findProduct(starRow,pageSize);*/
		 PageHelper.startPage(current, pageSize);
		 List<Product> findProduct = productMapper.findPageProduct();
		 
		

		 PageInfo<Product> pageinfo = new PageInfo<>(findProduct);
		 
		 PageBean<Product> pagebean = new PageBean<>();
		 pagebean.setCurrent(current);
		 pagebean.setItems(pageinfo.getList());
		 pagebean.setTaltal(pageinfo.getPages());
		 
		return pagebean;
	}

	@Override
	public Integer delete(String id) {
		Integer count = productMapper.updatetype(id);
		return count;
	}

	@Override
	public List<Catagory> listAllCatagory() {
		return productMapper.listAllCatagory();
	}

	@Override
	public Integer insert(Product product) {
		// TODO Auto-generated method stub
		return productMapper.insert(product);
	}

}
